//
//  TBRRecevePlaneTimePickerC.m
//  TBRentClient
//
//  Created by tonbright on 2018/5/17.
//  Copyright © 2018年 tonbright. All rights reserved.
//

#import "TBRRecevePlaneTimePickerC.h"
#import "YXDateHelpObject.h"

@interface TBRRecevePlaneTimePickerC ()<UIPickerViewDataSource,UIPickerViewDelegate>


@property (nonatomic,strong)NSArray *dateArray;
@property (nonatomic,strong)NSMutableArray *acutalDateArray;

//是否选中第一行呢

@end

@implementation TBRRecevePlaneTimePickerC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.pickerView.dataSource = self;
    self.pickerView.delegate = self;
    self.dateArray = [[YXDateHelpObject manager] receptPlaneFourDate:3];
    self.acutalDateArray = [[YXDateHelpObject manager] receptPlaneFourYearMonthDate:3];
    [self.pickerView selectRow:1 inComponent:0 animated:NO];
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    return self.dateArray.count;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component {
    return 40;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    NSString *dateStr = self.dateArray[row];
    if (row == 0) {
        return [NSString stringWithFormat:@"昨天-%@",dateStr];
    }
    else if (row == 1) {
        return [NSString stringWithFormat:@"今天-%@",dateStr];
    }else if (row == 2) {
        return [NSString stringWithFormat:@"明天-%@",dateStr];
    }else if (row == 3) {
        return [NSString stringWithFormat:@"后天-%@",dateStr];
    }
    return dateStr;
}



- (IBAction)cancleBtnClick:(UIButton *)sender {
    
    if (sender.tag == 10) {
        
        if (self.pickerViewCancleBtnBlock) {
            self.pickerViewCancleBtnBlock();
        }
    }else if (sender.tag == 20) {
        NSInteger dateIndex = [self.pickerView selectedRowInComponent:0];
        if (self.pickerViewSureBtnBlock) {
            self.pickerViewSureBtnBlock(self.dateArray[dateIndex],_acutalDateArray[dateIndex],dateIndex);
        }
        //记录选中的接机时间----------
    }
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    if (self.pickerViewCancleBtnBlock) {
        self.pickerViewCancleBtnBlock();
    }
}
@end
